<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container {
            width: 500px;
            height: 120px;
            color: grey;
            text-align: center;
            margin: 80px auto;
            border: solid 1px #b66161;
            border-radius: 15px;
        }
        
        .imges {
            width: 300px;
            height: 50px;
            line-height: 50px;
            margin: 20px auto;
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="imges">
            <img data-flag="true" src="./imgs/star2.png">
            <img data-flag="true" src="./imgs/star2.png">
            <img data-flag="true" src="./imgs/star2.png">
            <img data-flag="true" src="./imgs/star2.png">
            <img data-flag="true" src="./imgs/star2.png">
        </div>
        你给了<span class="info">0</span>颗星的点赞，感谢你的评价！
    </div>
</body>
<script>
    var imgs = document.querySelectorAll('.imges img'),
        sps = document.querySelector('.container span'),
        sum = 0;
    for (var i = 0; i < imgs.length; i++) {
        imgs[i].onclick = function() {
            sum = 0;
            if (this.getAttribute('data-flag') == 'true') {
                this.setAttribute('src', './imgs/star1.png');
                this.setAttribute('data-flag', 'false');
            } else {
                this.setAttribute('src', './imgs/star2.png');
                this.setAttribute('data-flag', 'true');
            }
            for (var j = 0; j < imgs.length; j++) {
                if (imgs[j].getAttribute('data-flag') == 'false') {
                    sum += 1;
                } else {
                    continue;
                }
            }
            sps.innerHTML = sum;
        }
    }
</script>
</body>

</html>